package com.tongji.housediy.model
{
	import com.tongji.housediy.vo.Province;
	import com.tongji.housediy.vo.TempCantavil;
	import com.tongji.housediy.vo.Type;
	
	import mx.collections.ArrayCollection;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/6/
	 */ 
	
	public class CantavilModel extends Actor
	{
		[Bindable]
		public var tempCantavils:ArrayCollection;
		[Bindable]
		public var firstCities:ArrayCollection = new ArrayCollection();
		[Bindable]
		public var secondCities:ArrayCollection;
		[Bindable]
		public var cantavils:ArrayCollection = new ArrayCollection();
		
		[Bindable]
		public var cantavilNameArrayCollection:ArrayCollection = new ArrayCollection();
	
		[Bindable]
		public var cityArray:ArrayCollection;
		
		[Bindable]
		public var cantavilList:ArrayCollection = new ArrayCollection();
		
		[Bindable]
		public var AGCityArray:ArrayCollection = new ArrayCollection();
		public var HJCityArray:ArrayCollection = new ArrayCollection();
		public var LSCityArray:ArrayCollection = new ArrayCollection();
		public var TZCityArray:ArrayCollection = new ArrayCollection();
		
		public function CantavilModel()
		{
			super();
		}
		
		public function updateCityModel(cityArray:ArrayCollection):void
		{
			this.cityArray = cityArray;
			for each(var province:Province in cityArray)
			{
				switch(province.proviceType)
				{
					case 1:
						AGCityArray.addItem(province);
						break;
					case 2:
						HJCityArray.addItem(province);
						break;
					case 3:
						LSCityArray.addItem(province);
						break;
					case 4:
						TZCityArray.addItem(province);
						break;
				}
			}
		}
		
		public function updateCantavil(tempCantavils:ArrayCollection):void
		{
			this.tempCantavils = tempCantavils;
			var i:int;
			for(i = 0; i < tempCantavils.length; i++)
			{
				var tempCantavil:TempCantavil = tempCantavils[i] as TempCantavil;
				firstCities.addItem(tempCantavil.firstCity);
				/*secondCities = new ArrayCollection(tempCantavil.secondCities.toArray());*/
				//secondCities.addItem(tempCantavil.secondCities);
//				secondCities.addAll(tempCantavil.secondCities);
				//cantavils.addAll(tempCantavil.cantavils);
				/*for(var k:int = 0; k < tempCantavil.secondCities.length; k++)
				{
					
				}*/
			}
			secondCities = new ArrayCollection((tempCantavils[0] as TempCantavil).secondCities.toArray());
			cantavils = new ArrayCollection((tempCantavils[0] as TempCantavil).cantavils.toArray());
			
		}
		
		public function updateCantavilResult(cantavilModel:ArrayCollection):void
		{
			cantavilList = cantavilModel;
		}
		
		public function updateCantavilModel(cantavilModel:ArrayCollection):void
		{
			if (cantavilModel.length == 0)
			{
				cantavilNameArrayCollection.removeAll();
			}
			else if (cantavilModel.length > 0)
			{
				cantavilNameArrayCollection = cantavilModel;
			}
		}

		public function filterSecondCity(type:Type):void
		{
			for each(var tempCantavil:TempCantavil in tempCantavils)
			{
				if(tempCantavil.firstCity == type)
				{
					secondCities = tempCantavil.secondCities;
					secondCities.refresh();
					cantavils = tempCantavil.cantavils;
					cantavils.refresh();
				}					
			}
		}
		
	}
}